package com.example.spb_rabbitmq2.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: climber zheng
 * @Desc:
 * @create: 2023-10-20 21:19
 **/
@Configuration
@Slf4j
public class RabbitMQConfig {
    public static final String SIMPLEQUEUE = "simpleQueue01";
    public static final String DIRECTQUEUE01 = "queue_direct_log";
    public static final String DIRECTQUEUE02 = "queue_direct_data";
    public static final String DIRECTEXCHANGE = "directExchange";
    public static final String ROUTINGKEY01DIRECT = "queue.log";
    public static final String ROUTINGKEY02DIRECT = "queue.data";

    public static final String FANOUTQUEUE01 = "queue_fanout01";
    public static final String FANOUTQUEUE02 = "queue_fanout02";
    public static final String FANOUTEXCHANGE = "fanoutExchange";

    public static final String QUEUETopic01 = "queue_topic_log";
    public static final String QUEUETopic02 = "queue_topic_data";
    public static final String TopicEXCHANGE = "topicExchange";
    public static final String ROUTINGKEY01 = "log.queue.#";
    public static final String ROUTINGKEY02 = "data.queue.#";

//    简单模式
    @Bean
    public Queue queue() {
        return new Queue(SIMPLEQUEUE, true);
    }

//    路由模式
    @Bean
    public Queue directQueue01() {
        return new Queue(DIRECTQUEUE01);
    }

    @Bean
    public Queue directQueue02() {
        return new Queue(DIRECTQUEUE02);
    }

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECTEXCHANGE);
    }

    @Bean
    public Binding directBinding01() {
        return BindingBuilder.bind(directQueue01()).to(directExchange()).with(ROUTINGKEY01DIRECT);
    }

    @Bean
    public Binding directBinding02() {
        return BindingBuilder.bind(directQueue02()).to(directExchange()).with(ROUTINGKEY02DIRECT);
    }
//    发布订阅模式
//    fanout exchange
    @Bean
    public Queue FanoutQueue01() {
        return new Queue(FANOUTQUEUE01);
    }
    @Bean
    public Queue FanoutQueue02() {
        return new Queue(FANOUTQUEUE02);
    }

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(FANOUTEXCHANGE);
    }

    @Bean
    public Binding binding01() {
        return BindingBuilder.bind(FanoutQueue01()).to(fanoutExchange());
    }
    @Bean
    public Binding binding02() {
        return BindingBuilder.bind(FanoutQueue02()).to(fanoutExchange());
    }
// 通配符模式
// Topic exchange
    @Bean
    public Queue QUEUETopic01() {
        return new Queue(QUEUETopic01);
    }

    @Bean
    public Queue QUEUETopic02() {
        return new Queue(QUEUETopic02);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TopicEXCHANGE);
    }

    @Bean
    public Binding bindingTopic01() {
        return BindingBuilder.bind(QUEUETopic01()).to(topicExchange()).with(ROUTINGKEY01);
    }

    @Bean
    public Binding bindingTopic02() {
        return BindingBuilder.bind(QUEUETopic02()).to(topicExchange()).with(ROUTINGKEY02);
    }


}
